const app = getApp()

Page({
  data: {
    loading: true,
    page: 0,
    company: [],
    card: [],
  },
  //监听页面初次载入完成
  onLoad: function (event) {
    var that = this;
    that.getApi();
  },
  //上拉加载
  onReachBottom: function () {
    var that = this;
    that.setData({
      loading: true,
    });
    that.getCard();
  },
  //获取分类
  getApi: function () {
    var that = this;
    var parms = {
      signkey: 'index',
    }
    app.api().Get('api/v1/bestbao/card/index', parms, function (result) {
      if (result.code == 200) {
        that.setData({
          company: result.data,
        });
        that.getCard();
      }
    })
  },
  //获取API
  getCard: function () {
    let that = this;
    if (that.data.loading) {
      var parms = {
        page: that.data.page + 1,
      }
      app.api().Get('api/v1/bestbao/card/engineer', parms, function (result) {
        if (result.code == 200) {
          var card = that.data.card;
          for (let i in result.data) {
            card.push(result.data[i]);
          }
          that.setData({
            card: card,
            page: parms.page,
          });
        }
      })
      that.setData({
        loading: false,
      });
    }
  },
  //拨打电话
  callPhone: function (e) {
    app.callPhone(e);
  },
  /**
    * 用户点击右上角分享
    */
  onShareAppMessage: function () {
    return {
      title: this.data.company.title,
      path: '/pages/card?ucode=' + app.globalData.loginuser.ucode
    }
  }
})